//
//  AppDelegate.m
//  I-want-go
//
//  Created by dllo on 15/10/21.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "CLspecialViewController.h"
#import "CLstrollViewController.h"
#import "CLdisgnerViewController.h"
#import "CLmyViewController.h"
#import "UMSocial.h"
#import "MobClick.h"
#import "CLgoViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc {
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    CLspecialViewController *specialVC = [[CLspecialViewController alloc] init];
    UINavigationController *specialNaVC = [[UINavigationController alloc] initWithRootViewController:specialVC];
    specialNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"专题" image:[UIImage imageNamed:@"zhuanti.png"] tag:1001] autorelease];
    
    CLdisgnerViewController *disVC = [[CLdisgnerViewController alloc] init];
    UINavigationController *disNaVC = [[UINavigationController alloc] initWithRootViewController:disVC];
    disNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"设计师" image:[UIImage imageNamed:@"disgner.png"] tag:1003] autorelease];
    
    CLstrollViewController *strollVC = [[CLstrollViewController alloc] init];
    UINavigationController *strollNaVC = [[UINavigationController alloc] initWithRootViewController:strollVC];
    strollNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"随心逛" image:[UIImage imageNamed:@"str.png"] tag:1005] autorelease];
    
    CLmyViewController *myVC = [[CLmyViewController alloc] init];
    UINavigationController *myNaVC = [[UINavigationController alloc] initWithRootViewController:myVC];
    myNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"user.png" ]  tag:1007] autorelease];
    

    
    
    self.tab = [[UITabBarController alloc] init];
    self.tab.viewControllers = @[specialNaVC, disNaVC, strollNaVC, myNaVC];
    self.window.rootViewController = self.tab;
    
    [specialVC release];
    [specialNaVC release];
    [disNaVC release];
    [disVC release];
    [strollNaVC release];
    [strollVC release];
    [myVC release];
    [myNaVC release];
    // 设置外观tabbar
    self.tab.tabBar.translucent = NO;
    self.tab.tabBar.barTintColor = [UIColor whiteColor];
    
    //    将channelId:@"Web" 中的Web 替换为您应用的推广渠道。channelId为nil或@""时，默认会被当作@"App Store"渠道。
    [MobClick startWithAppkey:@"56389acb67e58ef61f00030c" reportPolicy:BATCH   channelId:@""];
    
    [UMSocialData setAppKey:@"56389acb67e58ef61f00030c"];
    
        // (分享) 友好界面
        CGSize size = [UIScreen mainScreen].bounds.size;
    
        UIImageView *imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)] autorelease];
        imageView.image = [UIImage imageNamed:@"good.png"];
    
        [self.tab.view addSubview:imageView];
    
        [UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionTransitionCurlDown animations:^{
            imageView.alpha = 0;
    
        } completion:^(BOOL finished) {
    
            [imageView removeFromSuperview];
        }];
    
    
    
    
    //获取沙盒中的版本号
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *key = (NSString *)kCFBundleVersionKey;
    NSString *sandBoxVersion = [defaults valueForKeyPath:key];
    // 获取当前版本号
    NSDictionary *md = [NSBundle mainBundle].infoDictionary;
    NSString *currentVersion = md[key];
    
    NSLog(@"%@", NSHomeDirectory());
//    NSLog(@"%ld", NSOrderedDescending);
    if ([currentVersion compare:sandBoxVersion] == NSOrderedDescending)
    {
//        NSLog(@"ss ");
        // 存储当前版本号
        [defaults setObject:currentVersion forKey:key];
        //锁定当前线程
        [defaults synchronize];
        // 第一次使用当前版本  显示引导页
        [self showGuidePage];
    }
    else
    {
//        NSLog(@"sssdsf");
        // 不是第一次使用当前版本  显示主页面
        [self.window setRootViewController:self.tab];
        
    }
      return YES;
}
//////
- (void)showGuidePage
{
    CLgoViewController *goVC = [[CLgoViewController alloc] init];
    [self.window setRootViewController:goVC];
}





- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
